﻿using ManYan.Application;
using ManYan.Application.VO;
using ManYan.Common;
using ManYan.Domain.Model.Entity;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace ManYan.Api.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ExamContentController : BaseController<tb_exam_content,ExamContent>
    {
        public ExamContentController(IBaseAppService<tb_exam_content> baseAppService, IHttpContextAccessor httpContextAccessor) : base(baseAppService, httpContextAccessor)
        {
           
        }
        [HttpPost]
        public override Res<List<tb_exam_content>> Get(ExamContent t)
        {
            System.Linq.Expressions.Expression<Func<tb_exam_content, bool>> expression = LamdaHelper.True<tb_exam_content>();
            if (t.cateId != Guid.Empty)
                expression.And(x=>x.CateId==t.cateId);
            if (!string.IsNullOrEmpty(t.title))
                expression.And(x => x.Title.IndexOf(t.title)>0);
            return _baseAppService.LoadEntityEnumerable(expression, x => x.CreatDateTime, "desc", t.pageIndex, t.pageSize);
        }
        [HttpPut("{Id}")]
        public override Res Put(Guid Id, tb_exam_content value)
        {
            tb_exam_content? model = _baseAppService.WhereLoadEntity(x => x.Id == Id).Data as tb_exam_content;
            if(model!=null)
            {
                model.Id = Id;  
                model.Title = value.Title;
                model.Content = value.Content;
                model.CateId = value.CateId;
                model.Author = value.Author;
                model.Source = value.Source;
                return _baseAppService.UpdateEntity(model);
            }
            throw new Exception("");
        }

        //public override Res Get(Guid id)
        //{
        //    System.Linq.Expressions.Expression<Func<tb_exam_content, bool>> expression = x => x.Id == id;
        //    return _baseAppService.WhereLoadEntity(expression);
        //}


    }
}
